package com.cyzy.controller;

import com.cyzy.dto.Result;
import com.cyzy.dto.SignInDto;
import com.cyzy.dto.SignInResultDto;
import com.cyzy.service.SignInService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/signin")
public class SignInController {

    @Autowired
    private SignInService signInService;
    
    @GetMapping("/info/{userId}")
    public Result getSignInInfo(@PathVariable("userId") Long userId) {
        try {
            SignInDto signInInfo = signInService.getSignInInfo(userId);
            return Result.ok().data("signInInfo", signInInfo);
        } catch (Exception e) {
            e.printStackTrace(); // 打印完整的异常堆栈
            return Result.error().message("获取签到信息失败：" + e.getMessage());
        }
    }
    
    @PostMapping("/sign/{userId}")
    public Result signIn(@PathVariable("userId") Long userId) {
        try {
            SignInResultDto result = signInService.signIn(userId);
            if (result.getSuccess()) {
                return Result.ok().data("result", result);
            } else {
                return Result.error().message(result.getMessage());
            }
        } catch (Exception e) {
            e.printStackTrace(); // 打印完整的异常堆栈
            return Result.error().message("签到失败：" + e.getMessage());
        }
    }
}
